﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Reflection;

namespace MShop.Core.Domain
{
    [MetadataType(typeof(Pay_Validation))]
    public partial class Pay
    {
        public Pay()
        {
            this.HandlingCharge = 0;
        }

        public Pay(IPayModel payModel)
        {
            this.HandlingCharge = 0;
            this.PayModel = payModel;
        }

        public string HandlingChargeString
        {
            get
            {
                if (this.IsPercent)
                {
                    return (this.HandlingCharge *100).ToString() + "%";
                }
                return this.HandlingCharge.ToString();
            }
        }


        public void SetPayModel(IPayModel payModel)
        {
            this.PayModel = payModel;
        }

        public IPayModel PayModel
        {
            get;
            private  set;
        }

      

        public IEnumerable<int> CurrenyUnitIds
        {
            get
            {
                if (string.IsNullOrEmpty(this.CurrenyUnits))
                {
                    return Enumerable.Empty<int>();
                }
                else
                {
                    List<int> list = new List<int>();
                    foreach (string s in this.CurrenyUnits.Split(','))
                    {
                        list.Add(int.Parse(s));
                    }
                    return list;
                }
            }
        }
    
    }

    public class Pay_Validation
    {  
         [DisplayName("名称")]
         [System.ComponentModel.DataAnnotations.Required(ErrorMessage = "名称不能为空")]
         public string PayName { get; set; }
        [System.ComponentModel.DataAnnotations.Required(ErrorMessage = "货币类型不能为空")]
         [DisplayName("货币类型")]
         public string CurrenyUnits { get; set; }

         [DisplayName("接口类型")]
         public string PayType { get; set; }

         [DataType(DataType.MultilineText)]
         [DisplayName("描述")]
         public string PayDesc { get; set; }


         [DisplayName("排序")]
         public int Sort { get; set; }
         [System.ComponentModel.DataAnnotations.Required(ErrorMessage = "手续费不能为空")]
         [Range(0,10000000000d,ErrorMessage="手续费超出范围")]
         [DisplayName("手续费")]
         public decimal HandlingCharge { get; set; }
    }
}